﻿<from class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-block">
            <input type="password" name="oldpassword" lay-verify="required" autocomplete="off"
                   placeholder="请输入原密码" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newpassword" lay-verify="newpassword" id="newpassword" autocomplete="off"
                   placeholder="请输入新密码" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="请确认密码"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center;">
        <button class="layui-btn" lay-submit="" lay-filter="password">确认修改</button>
    </div>
</from>
<script type="text/javascript">
    layui.define(['layer', 'form'], function (exports) {
        var form = layui.form;
        var $ = layui.jquery;

        //自定义验证
        form.verify({
            newpassword: [/^[\S]{6,12}$/, '密码必须6到12位']
            , password: function (value) {
                var repassvalue = $('#newpassword').val();
                if (value != repassvalue) {
                    return '两次输入的密码不一致!';
                }
            }
        })
        ;

        form.on('submit(password)', function (data) {
            var index = layer.load(1);
            setTimeout(function () {
                workUtils.ajaxPost('../user/editpass',data.field,function (result) {
                    layer.close(index);
                    workUtils.msg(result);
                });
            }, 400);
            return false;
        });
    });
</script>